<template>
    <div class="box">
        
      <div class="warp">
          <h2>三里香点餐系统后台管理</h2>
         <input type="text" placeholder="请输入用户名" v-model="username">
         <input type="password" placeholder="密码" v-model="password">
          
          <button @click="denglu">登录</button>
          <p @click="zhuce">无账号，去注册</p>
      </div>
    </div>
</template>

<script>
import {ajax_login} from '../ajax/index'
export default {
    name: '',
    data(){
        return{
            username:'',
            password:''
        }
    },
    methods:{
        zhuce(){
            this.$router.push("/register");
        },
        denglu(){
            ajax_login({
                username:this.username,
                password:this.password,
            }).then(data=>{
                console.log(data);
                if(data.code==1){
                    this.$store.commit("setUser",data.data[0])
                      alert(data.msg);
                this.$router.push("/home")
                }else{
                    // console.log(data)
                    alert(data.msg)
                    
                    this.$router.push("/")
                }
                
            })
        }
    }
}
</script>

<style scoped>
.box{
    width: 100vw;
    height: 100vh;
    background:url("../assets/bei.jpg") no-repeat ;
    background-size: 100% 100%;
    text-align: center;
    position: relative;
    top: 0;
    z-index: 100;
}
.warp{
    width: 380px;
    height: 240px;
    background-color: white;
    border-radius: 8px;
    position: absolute;
    top: 0;
    left:0;
    right:0;
    bottom: 0;
    margin: auto;
}
h2{
    color:white;
    position: absolute;
    top:-70px;
    left: 85px;
}
input{
    width: 85%;
    margin: 0px auto;
    margin-top: 25px;
    border: none;
    outline: none;
    border: 1px solid gray;
    border-radius: 5px;
    padding: 8px 8px;
    background-color: #fffcc8;
}
button{
    outline: none;
    border: none;
    width: 90%;
    margin:20px auto;
    text-align: center;
    background-color: rgb(47, 255, 141);
    font-size: 18px;
    padding: 5px 0;
    color: white;
    border-radius: 5px;
}
p{
   position: absolute;
   right: 20px;
   bottom: 40px;
   color: blue;
   text-decoration: underline;
}

</style>